import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
plt.rcParams["font.family"] = ["SimHei"]
plt.rcParams["axes.unicode_minus"] = False

def get_dish_radar_data():
    df = pd.read_excel('餐饮连锁数据_菜品信息_cleaned.xlsx')
    df['价格评分'] = 5 - ((df['单价(元)'] - df['单价(元)'].min()) / (df['单价(元)'].max() - df['单价(元)'].min())) * 4
    df['价格评分'] = df['价格评分'].round(1)
    target_dishes = df.iloc[[0, 2, 5, 8, 10]]
    return target_dishes

dish_data = get_dish_radar_data()
labels = ['口味评分', '分量评分', '价格评分', '颜值评分', '上菜速度评分']
n = len(labels)

dish_names = dish_data['菜品名称'].tolist()
dish_scores = []
for idx in dish_data.index:
    scores = [
        dish_data.loc[idx, '口味评分'],
        dish_data.loc[idx, '分量评分'],
        dish_data.loc[idx, '价格评分'],
        dish_data.loc[idx, '颜值评分'],
        dish_data.loc[idx, '上菜速度评分']
    ]
    dish_scores.append(scores)

angles = np.linspace(0, 2*np.pi, n, endpoint=False).tolist()
closed_scores = []
closed_angles = angles + [angles[0]]
closed_labels = labels + [labels[0]]
for score in dish_scores:
    closed_scores.append(score + [score[0]])

plt.figure(figsize=(10, 8), dpi=100)
ax = plt.subplot(111, polar=True)

colors = ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd']
markers = ['o', 's', '^', 'D', 'p']
for i, (score, name, color, marker) in enumerate(zip(closed_scores, dish_names, colors, markers)):
    ax.plot(closed_angles, score, f'{marker}-', linewidth=2, label=name, color=color)
    ax.fill(closed_angles, score, alpha=0.15, color=color)

ax.set_thetagrids(np.degrees(angles), labels)
ax.set_ylim(0, 5)
ax.set_title('餐饮连锁菜品多维度评分雷达图（用于菜品优化）', fontsize=16, pad=30)
ax.grid(True)
plt.legend(loc='upper right', bbox_to_anchor=(1.3, 1.1), fontsize=10)

plt.tight_layout()
plt.savefig('菜品多维度评分雷达图.png', dpi=150, bbox_inches='tight')
plt.show()